package com.heisenhub.common.oauth.config;


import com.heisenhub.common.oauth.controller.BaseController;
import com.heisenhub.common.oauth.hander.ApiResourceOpenHander;
import com.heisenhub.common.oauth.hander.XmAccessDeniedHandler;
import com.heisenhub.common.oauth.hander.XmAuthExceptionEntryPoint;
import com.heisenhub.common.oauth.interceptor.XmServerProtectInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.servlet.HandlerInterceptor;

public class XmOauthConfigure {


    @Bean
    @ConditionalOnMissingBean(name = "accessDeniedHandler")
    public XmAccessDeniedHandler accessDeniedHandler() {
        return new XmAccessDeniedHandler();
    }

    @Bean
    @ConditionalOnMissingBean(name = "authenticationEntryPoint")
    public XmAuthExceptionEntryPoint authenticationEntryPoint() {
        return new XmAuthExceptionEntryPoint();
    }


    @Bean
    @ConditionalOnMissingBean(name = "apiResourceOpenHander")
    public ApiResourceOpenHander apiResourceOpenHander() {
        return new ApiResourceOpenHander();
    }


    @Bean
    @ConditionalOnMissingBean(name = "passwordEncoder")
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();  //BCryptPasswordEncoder的特点就是，对于一个相同的密码，每次加密出来的加密串都不同：
    }

    @Bean
    @ConditionalOnMissingBean(name = "baseController")
    public BaseController baseController() {
        return new BaseController();  //
    }


    @Bean
    @ConditionalOnMissingBean(name = "xmServerProtectInterceptor")
    public HandlerInterceptor xmServerProtectInterceptor() {
        return new XmServerProtectInterceptor();
    }

}
